<!DOCTYPE html>
<html  xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>Signin Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/css/signin.css}" rel="stylesheet">
	</head>

	<body class="text-center">
			<form class="form-signin" th:action="@{/Customer/login}" >
			<img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">
			<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
			<label class="sr-only">Username</label>
			<input type="text" class="form-control" placeholder="Username" th:id="Username"  name="Username" required="" autofocus="">
			<label class="sr-only">Password</label>
			<input type="password" class="form-control" th:id="password" placeholder="Password" required="" name="Password">
				<div class="form-group">
					<label>验证码</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="code" name="code" placeholder="验证码">
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<img src="/Customer/getCode" id="codeImg" onclick="refresh()" alt="">
					</div>
				</div>
				<div class="checkbox mb-3">
				<label>
          <input type="checkbox" value="remember-me"> Remember me
				</label>
				<li class="layui-this" style="color: red"  th:text="${msg == null?'请登录':msg}" ></li>
			</div>
			<button class="btn btn-lg btn-primary btn-block" type="submit" >Sign in</button>
			<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
			<a class="btn btn-sm">中文</a>
			<a class="btn btn-sm">English</a>
		</form>
			<script>
				function login() {
					var Username = document.getElementById("Username").value;
					var password  = document.getElementById("password").value;
					var code = document.getElementById("code").value;
					console.log(code);
					$.ajax({
						url:"/Customer/login",
						type:"get",
						data:{"Username":Username,
							  "Password":password,
						      "code":code},
						dataType:"json",
						contentType:"application/json",
						error: function (data) {
							location.href = "listbook?bookName="+text;
							alert("登录失败"+data.description);
						},
						success:function (data) {
							location.href = "listbook?bookName="+text;
							alert("登录成功");
						}
					});
				}
			</script>
			<script>
				/* 刷新验证码 */
				function refresh() {
					document.getElementById("codeImg").src = "/Customer/getCode?time=" + new Date().getTime();
				}
			</script>
	</body>
</html>